﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using UnityEngine.EventSystems;

public class CtrlHuman : BaseHuman //继承
{
    

    // Start is called before the first frame update
    new void Start()
    {   
        base.Start();  //实现此类需要调用的功能
    }

    // Update is called once per frame
    new void Update()
    {
        base.Update(); //实现此类需要调用的功能
        //鼠标点击地面移动
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            PointerEventData data = new PointerEventData(UnityEngine.EventSystems.EventSystem.current);
            data.position = Input.mousePosition;
            List<RaycastResult> rs = new List<RaycastResult>();
            EventSystem.current.RaycastAll(data, rs);

            // 点在UI上
            if (rs.Count > 0)
                return;

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.tag.Equals("Plane"))
                {
                    MoveTo(hit.point);
                    //将移动数据发送给Server

                    //传递Client具体信息会加大网络使用率，反则增加服务器运算量
                    Msg msg = new Msg()
                    {
                        Command = "Move",
                        Client = "",
                        Value = hit.point.x+","+hit.point.y+","+hit.point.z
                    };
                    NetManager.Manager.SendAsync(msg);
                }
            }
        }
    }

}
